package com.chen.blue.converter.system;

import com.chen.blue.domain.dto.system.DeptDto;
import com.chen.blue.domain.dto.system.MenuButtonDto;
import com.chen.blue.domain.dto.system.MenuDirectoryDto;
import com.chen.blue.domain.dto.system.MenuDto;
import com.chen.blue.domain.dto.system.update.DeptDtoEdit;
import com.chen.blue.domain.dto.system.update.MenuButtonDtoEdit;
import com.chen.blue.domain.dto.system.update.MenuDirectoryDtoEdit;
import com.chen.blue.domain.dto.system.update.MenuDtoEdit;
import com.chen.blue.domain.model.system.DeptModel;
import com.chen.blue.domain.model.system.MenuModel;
import com.chen.blue.domain.vo.system.DeptVo;
import com.chen.blue.domain.vo.system.MenuVo;
import org.springframework.cglib.beans.BeanCopier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Created By CLT On 2024/4/29.
 */
@SuppressWarnings("all")
public abstract class MenuConverter {


    private static final BeanCopier modelToVo = BeanCopier.create(MenuModel.class, MenuVo.class, false);

    private static final BeanCopier dtoToModel = BeanCopier.create(MenuDto.class, MenuModel.class, false);
    private static final BeanCopier dtoDirectoryToModel = BeanCopier.create(MenuDirectoryDto.class, MenuModel.class, false);
    private static final BeanCopier dtoButtonToModel = BeanCopier.create(MenuButtonDto.class, MenuModel.class, false);

    private static final BeanCopier dtoEditToModel = BeanCopier.create(MenuDtoEdit.class, MenuModel.class, false);
    private static final BeanCopier dtoDirectoryEditToModel = BeanCopier.create(MenuDirectoryDtoEdit.class, MenuModel.class, false);
    private static final BeanCopier dtoButtonEditToModel = BeanCopier.create(MenuButtonDtoEdit.class, MenuModel.class, false);


    /**
     * model->vo
     *
     * @param model
     * @return
     */
    public static MenuVo modelToVo(MenuModel model) {
        if (Objects.isNull(model)) {
            return null;
        }
        MenuVo menuVo = new MenuVo();
        modelToVo.copy(model, menuVo, null);
        return menuVo;
    }

    /**
     * model->volist
     *
     * @param modelList
     * @return
     */
    public static List<MenuVo> modelToVoList(List<MenuModel> modelList) {
        if (modelList.size() == 0) {
            return null;
        }

        List<MenuVo> menuVoList = new ArrayList<>();
        for (MenuModel menuModel : modelList) {
            menuVoList.add(modelToVo(menuModel));
        }

        return menuVoList;

    }


    /**
     * dto->model
     *
     * @param menuDto
     * @return
     */
    public static MenuModel dtoToModel(MenuDto menuDto) {

        if (Objects.isNull(menuDto)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoToModel.copy(menuDto, menuModel, null);
        return menuModel;

    }

    public static MenuModel dtoToModel(MenuDirectoryDto menuDirectoryDto) {

        if (Objects.isNull(menuDirectoryDto)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoDirectoryToModel.copy(menuDirectoryDto, menuModel, null);
        return menuModel;

    }

    public static MenuModel dtoToModel(MenuButtonDto menuButtonDto) {

        if (Objects.isNull(menuButtonDto)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoButtonToModel.copy(menuButtonDto, menuModel, null);
        return menuModel;

    }

    /**
     * editDto->model
     *
     * @param userDtoEdit
     * @return
     */
    public static MenuModel dtoEditToModel(MenuDtoEdit menuDtoEdit) {

        if (Objects.isNull(menuDtoEdit)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoEditToModel.copy(menuDtoEdit, menuModel, null);
        return menuModel;

    }

    public static MenuModel dtoEditToModel(MenuDirectoryDtoEdit menuDirectoryDtoEdit) {

        if (Objects.isNull(menuDirectoryDtoEdit)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoDirectoryEditToModel.copy(menuDirectoryDtoEdit, menuModel, null);
        return menuModel;

    }

    public static MenuModel dtoEditToModel(MenuButtonDtoEdit menuButtonDtoEdit) {

        if (Objects.isNull(menuButtonDtoEdit)) {
            return null;
        }

        MenuModel menuModel = new MenuModel();
        dtoButtonEditToModel.copy(menuButtonDtoEdit, menuModel, null);
        return menuModel;

    }


}
